package com.vca.admin.controller;

import com.vca.common.page.CommonPage;
import com.vca.common.request.PageParamRequest;
import com.vca.common.request.VhallSetCallbackRequest;
import com.vca.common.request.VhallSetKeyRequest;
import com.vca.common.response.VhallAdminListResponse;
import com.vca.common.response.VhallGetCallbackResponse;
import com.vca.common.response.VhallGetKeyResponse;
import com.vca.common.result.CommonResult;
import com.vca.service.service.VhallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Li
 * @program VCA_Mini_Program
 * @description 微吼后台控制器
 * @classname VhallController
 * @since 2022/12/19 13:38:45
 **/

@Slf4j
@RestController("VhallController")
@RequestMapping("api/admin/vhall")
@Api(tags = "微吼控制器")
public class VhallController {

    @Autowired
    private VhallService vhallService;


    /**
     * @description 获取微吼直播列表
     * @author Li
     * @date 2022/12/19 13:43
     * @return com.vca.common.result.CommonResult
     */
    @PreAuthorize("hasAuthority('admin:vhall:list')")
    @ApiOperation("获取直播列表")
    @GetMapping("/list")
    public CommonResult<CommonPage<VhallAdminListResponse>> list(String status, @ModelAttribute PageParamRequest pageParamRequest){
        CommonPage commonPage = CommonPage.restPage(vhallService.list(status,pageParamRequest));
        return CommonResult.success(commonPage);
    }


    /**
     * @description 设置微吼回调地址
     * @param request
     * @author Li
     * @date 2022/12/28 9:55
     * @return com.vca.common.result.CommonResult
     */
    @ApiOperation("设置微吼回调地址")
    @PostMapping("/setCallback")
    public CommonResult setCallback(@RequestBody VhallSetCallbackRequest request){
        return vhallService.setCallback(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * @description 查询回调事件
     * @author Li
     * @date 2022/12/28 10:18
     * @return com.vca.common.result.CommonResult
     */
    @ApiOperation("查询回调事件")
    @GetMapping("/getCallback")
    public CommonResult<VhallGetCallbackResponse> getCallback(){
        return CommonResult.success(vhallService.getCallback());
    }

    /**
     * @description 设置VhallKey值验证
     * @methodName setKey
     * @param request
     * @author Li
     * @date 2022/12/29 9:20
     * @return com.vca.common.result.CommonResult<java.lang.String>
     */
    @PreAuthorize("hasAuthority('admin:vhall:key:set')")
    @ApiOperation("设置VhallKey值验证")
    @PostMapping("/setKey")
    public CommonResult<String> setKey(@RequestBody VhallSetKeyRequest request){
        return CommonResult.success(vhallService.setKey(request));
    }

    /**
     * @description 获取VhallKey值参数
     * @methodName getKey
     * @author Li
     * @date 2022/12/30 11:25
     * @return com.vca.common.result.CommonResult<com.vca.common.response.VhallGetKeyResponse>
     */
    @PreAuthorize("hasAuthority('admin:vhall:key:get')")
    @ApiOperation("获取VhallKey值参数")
    @GetMapping("/getKey")
    public CommonResult<VhallGetKeyResponse> getKey(){
        return CommonResult.success(vhallService.getKey());
    }

}
